import React from 'react';
import store from "../store";
import {joinCart} from "../store/slice/cart";
import {useNavigate} from "react-router-dom";

function GoodsList(props) {
    const navigate = useNavigate();
    return (
        <div>
            {
                store.getState().goods.goodsList.map(item=>(
                    <div key={item.id}>
                        <p>商品名称：{item.goodsName}</p>
                        <p>商品价格：￥{item.goodsPrice.toFixed(2)}</p>
                        <button onClick={()=>{
                            store.dispatch(joinCart(item));
                            navigate("/cartList");
                        }}>加入购物车</button>
                        <hr/>
                    </div>
                ))
            }
        </div>
    );
}

export default GoodsList;